package com.opengms.HydroModelsIntegration.Dao;

import com.opengms.HydroModelsIntegration.Domain.InpData;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;

/**
 * 将从前台获取的json文件转为INP格式
 */
public class Json2Inp {


    private InpData inpData=new InpData();


    public InpData json2InpData(JSONObject jsonObject)
    {

        inpData.setTitleArrayList(getTitleFromJson(jsonObject.getJSONArray("titleArrayList")));
        inpData.setOption(getOptionFromJson(jsonObject.getJSONObject("option")));
        inpData.setEvaporation(getEvaporationFromJson(jsonObject.getJSONObject("evaporation")));
        inpData.setRaingageArrayList(getRaingageFromJson(jsonObject.getJSONArray("raingageArrayList")));
        inpData.setSubcatchmentArrayList(getSubcatchmentFromJson(jsonObject.getJSONArray("subcatchmentArrayList")));
        inpData.setSubareaArrayList(getSubareaFromJson(jsonObject.getJSONArray("subareaArrayList")));
        inpData.setInfiltrationArrayList(getInfiltrationFromJson(jsonObject.getJSONArray("infiltrationArrayList")));
        inpData.setJunctionArrayList(getJunctionFromJson(jsonObject.getJSONArray("junctionArrayList")));
        inpData.setOutfallArrayList(getOutfallFromJson(jsonObject.getJSONArray("outfallArrayList")));
        inpData.setStorageArrayList(getStorageFromJson(jsonObject.getJSONArray("storageArrayList")));
        inpData.setConduitArrayList(getConduitFromJson(jsonObject.getJSONArray("conduitArrayList")));
        inpData.setXscetionArrayList(getXscetionFromJson(jsonObject.getJSONArray("xscetionArrayList")));
        inpData.setLossesArrayList(getLossesFromJson(jsonObject.getJSONArray("lossesArrayList")));
        inpData.setCurveArrayList(getCurveFromJson(jsonObject.getJSONArray("curveArrayList")));
        inpData.setTimeseriesArrayList(getTimeseriesFromJson(jsonObject.getJSONArray("timeseriesArrayList")));
        inpData.setReport(getReportFromJson(jsonObject.getJSONObject("report")));
        inpData.setTagArrayList(getTagFromJson(jsonObject.getJSONArray("tagArrayList")));
        inpData.setMap(getMapFromJson(jsonObject.getJSONObject("map")));
        inpData.setCoordinateArrayList(getCoordinateFromJson(jsonObject.getJSONArray("coordinateArrayList")));
        inpData.setVerticeArrayList(getVerticeFromJson(jsonObject.getJSONArray("verticeArrayList")));
        inpData.setPolygonArrayList(getPolygonFromJson(jsonObject.getJSONArray("polygonArrayList")));
        inpData.setSymbolArrayList(getSymbolFromJson(jsonObject.getJSONArray("symbolArrayList")));

        return inpData;
    }


    private ArrayList<String> getTitleFromJson(JSONArray jsonArray)
    {
        ArrayList<String> TitleArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            TitleArrayList.add(jsonArray.get(i).toString());
        }
        return TitleArrayList;
    }
    private InpData.Option getOptionFromJson(JSONObject jsonObject)
    {

        InpData.Option option=inpData.new Option();
        option.setFlow_units(jsonObject.get("flow_units").toString());
        option.setInfiltration(jsonObject.get("infiltration").toString());
        option.setFlow_routing(jsonObject.get("flow_routing").toString());
        option.setLink_offsets(jsonObject.get("link_offsets").toString());
        option.setMin_slope(Float.parseFloat(jsonObject.get("min_slope").toString()));
        option.setAllow_ponding(jsonObject.get("allow_ponding").toString());
        option.setSkip_steady_state(jsonObject.get("skip_steady_state").toString());
        option.setIgnore_rainfall(jsonObject.get("ignore_rainfall").toString());
        option.setIgnore_routing(jsonObject.get("ignore_routing").toString());
        option.setStart_date(jsonObject.get("start_date").toString());
        option.setStart_time(jsonObject.get("start_time").toString());
        option.setReport_start_date(jsonObject.get("report_start_date").toString());
        option.setReport_start_time(jsonObject.get("report_start_time").toString());
        option.setEnd_date(jsonObject.get("end_date").toString());
        option.setEnd_time(jsonObject.get("end_time").toString());
        option.setSweep_start(jsonObject.get("sweep_start").toString());
        option.setSweep_end(jsonObject.get("sweep_end").toString());
        option.setDry_days(Float.parseFloat(jsonObject.get("dry_days").toString()));
        option.setReport_step(jsonObject.get("report_step").toString());
        option.setWet_step(jsonObject.get("wet_step").toString());
        option.setDry_step(jsonObject.get("dry_step").toString());
        option.setRouting_step(jsonObject.get("routing_step").toString());
        option.setInertial_damping(jsonObject.get("inertial_damping").toString());
        option.setNormal_flow_limited(jsonObject.get("normal_flow_limited").toString());
        option.setForce_main_equation(jsonObject.get("force_main_equation").toString());
        option.setVariable_step(Float.parseFloat(jsonObject.get("variable_step").toString()));
        option.setLengthening_step(Float.parseFloat(jsonObject.get("lengthening_step").toString()));
        option.setMin_surfarea(Float.parseFloat(jsonObject.get("min_surfarea").toString()));
        option.setMax_trials(Float.parseFloat(jsonObject.get("max_trials").toString()));
        option.setHead_tolerance(Float.parseFloat(jsonObject.get("head_tolerance").toString()));
        option.setSys_flow_tol(Float.parseFloat(jsonObject.get("sys_flow_tol").toString()));
        option.setLat_flow_tol(Float.parseFloat(jsonObject.get("lat_flow_tol").toString()));
        return option;
    }
    private InpData.Evaporation getEvaporationFromJson(JSONObject jsonObject)
    {
        InpData.Evaporation evaporation=inpData.new Evaporation();
        evaporation.setSelected_source(jsonObject.get("selected_source").toString());
        evaporation.setConstant(Float.parseFloat(jsonObject.get("constant").toString()));
        evaporation.setTimeseries(jsonObject.get("timeseries").toString());

        JSONArray fileJsonArray=jsonObject.getJSONArray("file");
        float[] file=new float[fileJsonArray.size()];
        for(int i=0;i<file.length;i++)
        {
            file[i]=Float.parseFloat(fileJsonArray.get(i).toString());
        }
        evaporation.setFile(file);

        JSONArray monthlyJsonArray=jsonObject.getJSONArray("monthly");
        float[] monthly=new float[monthlyJsonArray.size()];
        for(int i=0;i<monthly.length;i++)
        {
            monthly[i]=Float.parseFloat(monthlyJsonArray.get(i).toString());
        }

        evaporation.setMonthly(monthly);
        evaporation.setTemperature(jsonObject.get("temperature").toString());
        evaporation.setRecovery(jsonObject.get("recovery").toString());
        evaporation.setDryonly(jsonObject.get("dryonly").toString());
        return evaporation;
    }
    private ArrayList<InpData.Raingage> getRaingageFromJson(JSONArray jsonArray)
    {
        ArrayList<InpData.Raingage> raingageArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Raingage raingage=inpData.new Raingage();
            raingage.setGage(jsonArray.getJSONObject(i).get("gage").toString());
            raingage.setFormat(jsonArray.getJSONObject(i).get("format").toString());
            raingage.setInterval(jsonArray.getJSONObject(i).get("interval").toString());
            raingage.setScf(jsonArray.getJSONObject(i).get("scf").toString());
            raingage.setDatasource(jsonArray.getJSONObject(i).get("datasource").toString());
            raingage.setSeriesname(jsonArray.getJSONObject(i).get("seriesname").toString());
            raingage.setFilename(jsonArray.getJSONObject(i).get("filename").toString());
            raingage.setStationid(jsonArray.getJSONObject(i).get("stationid").toString());
            raingage.setRainunits(jsonArray.getJSONObject(i).get("rainunits").toString());
            ArrayList<String> description=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("description").size();j++)
            {
                description.add(jsonArray.getJSONObject(i).getJSONArray("description").get(j).toString());
            }
            raingage.setDescription(description);
        raingageArrayList.add(raingage);
        }

        return raingageArrayList;
    }

    private ArrayList<InpData.Subcatchment> getSubcatchmentFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Subcatchment> subcatchmentArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Subcatchment subcatchment=inpData.new Subcatchment();
            subcatchment.setSubcatchment(jsonArray.getJSONObject(i).get("subcatchment").toString());
            subcatchment.setRaingage(jsonArray.getJSONObject(i).get("raingage").toString());
            subcatchment.setOutlet(jsonArray.getJSONObject(i).get("outlet").toString());

            subcatchment.setArea(Float.parseFloat(jsonArray.getJSONObject(i).get("area").toString()));
            subcatchment.setImperv(Float.parseFloat(jsonArray.getJSONObject(i).get("imperv").toString()));
            subcatchment.setWidth(Float.parseFloat(jsonArray.getJSONObject(i).get("width").toString()));
            subcatchment.setSlope(Float.parseFloat(jsonArray.getJSONObject(i).get("slope").toString()));
            subcatchment.setCurblen(Float.parseFloat(jsonArray.getJSONObject(i).get("curblen").toString()));
            subcatchment.setSnowpack(jsonArray.getJSONObject(i).get("snowpack").toString());
            ArrayList<String> description=new ArrayList<>();

            for (int j = 0; j < jsonArray.getJSONObject(i).getJSONArray("description").size(); j++) {
                description.add(jsonArray.getJSONObject(i).getJSONArray("description").get(j).toString());
            }
            subcatchment.setDescription(description);

            subcatchmentArrayList.add(subcatchment);
        }
        return subcatchmentArrayList;

    }

    private ArrayList<InpData.Subarea> getSubareaFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Subarea> subareaArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Subarea subarea=inpData.new Subarea();
            subarea.setSubcatchment(jsonArray.getJSONObject(i).get("subcatchment").toString());
            subarea.setN_imperv(Float.parseFloat(jsonArray.getJSONObject(i).get("n_imperv").toString()));
            subarea.setN_perv(Float.parseFloat(jsonArray.getJSONObject(i).get("n_perv").toString()));
            subarea.setPctrouted(Float.parseFloat(jsonArray.getJSONObject(i).get("pctrouted").toString()));
            subarea.setPctzero(Float.parseFloat(jsonArray.getJSONObject(i).get("pctzero").toString()));
            subarea.setRouteto(jsonArray.getJSONObject(i).get("routeto").toString());
            subarea.setS_imperv(Float.parseFloat(jsonArray.getJSONObject(i).get("s_imperv").toString()));
            subarea.setS_perv(Float.parseFloat(jsonArray.getJSONObject(i).get("s_perv").toString()));

            subareaArrayList.add(subarea);
            //TODO 考虑要不要继续完成写入文件 感觉意义不大
        }
        return subareaArrayList;
    }

    private ArrayList<InpData.Infiltration> getInfiltrationFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Infiltration> infiltrationArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Infiltration infiltration=inpData.new Infiltration();
            infiltration.setSubcatchment(jsonArray.getJSONObject(i).get("subcatchment").toString());
            infiltration.setConductivity(Float.parseFloat(jsonArray.getJSONObject(i).get("conductivity").toString()));
            infiltration.setCurveNumber(Float.parseFloat(jsonArray.getJSONObject(i).get("curveNumber").toString()));
            infiltration.setDecay(Float.parseFloat(jsonArray.getJSONObject(i).get("decay").toString()));
            infiltration.setDrytime(Float.parseFloat(jsonArray.getJSONObject(i).get("drytime").toString()));

            infiltration.setInitialDeficit(Float.parseFloat(jsonArray.getJSONObject(i).get("initialDeficit").toString()));
            infiltration.setMaxinfil(Float.parseFloat(jsonArray.getJSONObject(i).get("maxinfil").toString()));
            infiltration.setMaxrate(Float.parseFloat(jsonArray.getJSONObject(i).get("maxrate").toString()));
            infiltration.setMinrate(Float.parseFloat(jsonArray.getJSONObject(i).get("minrate").toString()));
            infiltration.setSuction(Float.parseFloat(jsonArray.getJSONObject(i).get("suction").toString()));

            infiltrationArrayList.add(infiltration);
        }
        return infiltrationArrayList;
    }

    private ArrayList<InpData.Junction> getJunctionFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Junction> junctionArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Junction junction=inpData.new Junction();
            junction.setJunction(jsonArray.getJSONObject(i).get("junction").toString());
            junction.setAponded(Float.parseFloat(jsonArray.getJSONObject(i).get("aponded").toString()));


            ArrayList<String> description=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("description").size();j++)
            {
                description.add(jsonArray.getJSONObject(i).getJSONArray("description").get(j).toString());
            }
            junction.setDescription(description);


            junction.setInitdepth(Float.parseFloat(jsonArray.getJSONObject(i).get("initdepth").toString()));
            junction.setInvert(Float.parseFloat(jsonArray.getJSONObject(i).get("invert").toString()));

            junction.setMaxdepth(Float.parseFloat(jsonArray.getJSONObject(i).get("maxdepth").toString()));
            junction.setSurdepth(Float.parseFloat(jsonArray.getJSONObject(i).get("surdepth").toString()));


            junctionArrayList.add(junction);
        }
        return junctionArrayList;
    }

    private ArrayList<InpData.Outfall> getOutfallFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Outfall> outfallArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Outfall outfall=inpData.new Outfall();
            outfall.setOutfall(jsonArray.getJSONObject(i).get("outfall").toString());
            outfall.setGated(jsonArray.getJSONObject(i).get("gated").toString());


            ArrayList<String> description=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("description").size();j++)
            {
                description.add(jsonArray.getJSONObject(i).getJSONArray("description").get(j).toString());
            }
            outfall.setDescription(description);


            outfall.setInvert(Float.parseFloat(jsonArray.getJSONObject(i).get("invert").toString()));
            outfall.setStagedata(jsonArray.getJSONObject(i).get("stagedata").toString());

            outfall.setType(jsonArray.getJSONObject(i).get("type").toString());


            outfallArrayList.add(outfall);
        }
        return outfallArrayList;
    }

    private ArrayList<InpData.Storage> getStorageFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Storage> storageArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Storage storage=inpData.new Storage();

            ArrayList<String> description=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("description").size();j++)
            {
                description.add(jsonArray.getJSONObject(i).getJSONArray("description").get(j).toString());
            }
            storage.setDescription(description);

            storage.setStorage(jsonArray.getJSONObject(i).get("storage").toString());
            storage.setInvert(Float.parseFloat(jsonArray.getJSONObject(i).get("invert").toString()));
            storage.setMaxdepth(Float.parseFloat(jsonArray.getJSONObject(i).get("maxdepth").toString()));
            storage.setInitdepth(Float.parseFloat(jsonArray.getJSONObject(i).get("initdepth").toString()));
            storage.setShape(jsonArray.getJSONObject(i).get("shape").toString());
            storage.setCurvename(jsonArray.getJSONObject(i).get("curvename").toString());

            if(jsonArray.getJSONObject(i).getJSONArray("param").size()>0)
            {
                float[] param=new float[3];
                for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("param").size();j++)
                {
                    param[j]=(Float.parseFloat(jsonArray.getJSONObject(i).getJSONArray("param").get(j).toString()));
                }
                storage.setParam(param);
            }
            else
            {
                storage.setParam(null);
            }



            storage.setPonded(Float.parseFloat(jsonArray.getJSONObject(i).get("ponded").toString()));
            storage.setFevap(Float.parseFloat(jsonArray.getJSONObject(i).get("fevap").toString()));
            storage.setSeepage_exist(jsonArray.getJSONObject(i).get("seepage_exist").toString());
            if(storage.getSeepage_exist().equals("YES"))
            {
                float[] seepage=new float[3];
                for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("seepage").size();j++)
                {
                    seepage[j]=(Float.parseFloat(jsonArray.getJSONObject(i).getJSONArray("seepage").get(j).toString()));
                }
                storage.setSeepage(seepage);
            }
            else
            {
                storage.setSeepage(null);
            }


            storageArrayList.add(storage);
        }
        return storageArrayList;
    }

    private ArrayList<InpData.Conduit> getConduitFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Conduit> conduitArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Conduit conduit=inpData.new Conduit();

            ArrayList<String> description=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("description").size();j++)
            {
                description.add(jsonArray.getJSONObject(i).getJSONArray("description").get(j).toString());
            }
            conduit.setDescription(description);

            conduit.setConduit(jsonArray.getJSONObject(i).get("conduit").toString());
            conduit.setFromnode(jsonArray.getJSONObject(i).get("fromnode").toString());
            conduit.setTonode(jsonArray.getJSONObject(i).get("tonode").toString());

            conduit.setLength(Float.parseFloat(jsonArray.getJSONObject(i).get("length").toString()));
            conduit.setRoughness(Float.parseFloat(jsonArray.getJSONObject(i).get("roughness").toString()));
            conduit.setInoffset(Float.parseFloat(jsonArray.getJSONObject(i).get("inoffset").toString()));
            conduit.setOutoffset(Float.parseFloat(jsonArray.getJSONObject(i).get("outoffset").toString()));
            conduit.setInitflow(Float.parseFloat(jsonArray.getJSONObject(i).get("initflow").toString()));
            conduit.setMaxflow(Float.parseFloat(jsonArray.getJSONObject(i).get("maxflow").toString()));

            conduitArrayList.add(conduit);
        }
        return conduitArrayList;

    }

    private ArrayList<InpData.Xscetion> getXscetionFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Xscetion> xscetionArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Xscetion xscetion=inpData.new Xscetion();
            xscetion.setLink(jsonArray.getJSONObject(i).get("link").toString());
            xscetion.setShape(jsonArray.getJSONObject(i).get("shape").toString());


            xscetion.setGeom1(Float.parseFloat(jsonArray.getJSONObject(i).get("geom1").toString()));
            xscetion.setGeom2(Float.parseFloat(jsonArray.getJSONObject(i).get("geom2").toString()));
            xscetion.setGeom3(Float.parseFloat(jsonArray.getJSONObject(i).get("geom3").toString()));
            xscetion.setGeom4(Float.parseFloat(jsonArray.getJSONObject(i).get("geom4").toString()));
            xscetion.setBarrels(Integer.parseInt(jsonArray.getJSONObject(i).get("barrels").toString()));
            xscetion.setCulvertcode(jsonArray.getJSONObject(i).get("culvertcode").toString());

            xscetionArrayList.add(xscetion);
        }
        return xscetionArrayList;

    }

    private ArrayList<InpData.Losses> getLossesFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Losses> lossesArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Losses losses=inpData.new Losses();
            losses.setCulvert(jsonArray.getJSONObject(i).get("culvert").toString());


            losses.setEntry_loss_coeff(Float.parseFloat(jsonArray.getJSONObject(i).get("entry_loss_coeff").toString()));
            losses.setExit_loss_coeff(Float.parseFloat(jsonArray.getJSONObject(i).get("exit_loss_coeff").toString()));
            losses.setAvg_loss_coeff(Float.parseFloat(jsonArray.getJSONObject(i).get("avg_loss_coeff").toString()));
            losses.setFlap_gate(jsonArray.getJSONObject(i).get("flap_gate").toString());

            losses.setSeepage_loss_rate(Float.parseFloat(jsonArray.getJSONObject(i).get("seepage_loss_rate").toString()));

            lossesArrayList.add(losses);
        }
        return lossesArrayList;

    }

    private ArrayList<InpData.Curve> getCurveFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Curve> curveArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Curve curve=inpData.new Curve();
            curve.setCurve(jsonArray.getJSONObject(i).get("curve").toString());

            curve.setType(jsonArray.getJSONObject(i).get("type").toString());

            ArrayList<String> description=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("description").size();j++)
            {
                description.add(jsonArray.getJSONObject(i).getJSONArray("description").get(j).toString());
            }
            curve.setDescription(description);

            ArrayList<InpData.CurveXY> xyArrayList=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("xyArrayList").size();j++)
            {
                float x=Float.parseFloat(jsonArray.getJSONObject(i).getJSONArray("xyArrayList").getJSONObject(j).get("x_value").toString()) ;
                float y=Float.parseFloat(jsonArray.getJSONObject(i).getJSONArray("xyArrayList").getJSONObject(j).get("y_value").toString()) ;
                InpData.CurveXY xy=inpData.new CurveXY();
                xy.setX_value(x);
                xy.setY_value(y);
                xyArrayList.add(xy);
            }
            curve.setXyArrayList(xyArrayList);
            curveArrayList.add(curve);
        }
        return curveArrayList;

    }

    private ArrayList<InpData.Timeseries> getTimeseriesFromJson(JSONArray jsonArray)
    {

        ArrayList<InpData.Timeseries> timeseriesArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Timeseries timeseries=inpData.new Timeseries();

            timeseries.setTimeseries(jsonArray.getJSONObject(i).get("timeseries").toString());

            ArrayList<String> description=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("description").size();j++)
            {
                description.add(jsonArray.getJSONObject(i).getJSONArray("description").get(j).toString());
            }
            timeseries.setDescription(description);

            ArrayList<InpData.DateTimeValue> dateTimeValueArrayList=new ArrayList<>();
            for (int j=0;j<jsonArray.getJSONObject(i).getJSONArray("dateTimeValueArrayList").size();j++)
            {
                String date=jsonArray.getJSONObject(i).getJSONArray("dateTimeValueArrayList").getJSONObject(j).get("date").toString();
                String time=jsonArray.getJSONObject(i).getJSONArray("dateTimeValueArrayList").getJSONObject(j).get("time").toString();
                float value=Float.parseFloat(jsonArray.getJSONObject(i).getJSONArray("dateTimeValueArrayList").getJSONObject(j).get("value").toString());
                InpData.DateTimeValue dateTimeValue=inpData.new DateTimeValue();
                dateTimeValue.setDate(date);
                dateTimeValue.setTime(time);
                dateTimeValue.setValue(value);
                dateTimeValueArrayList.add(dateTimeValue);
            }
            timeseries.setDateTimeValueArrayList(dateTimeValueArrayList);
            timeseriesArrayList.add(timeseries);
        }
        return timeseriesArrayList;

    }

    private InpData.Report getReportFromJson(JSONObject jsonObject)
    {

        InpData.Report report=inpData.new Report();
        report.setInput(jsonObject.get("input").toString());
        report.setControls(jsonObject.get("controls").toString());

        if(jsonObject.getJSONArray("subcatchments").size()>0)
        {
            String[] subcatchments=new String[jsonObject.getJSONArray("subcatchments").size()];
            for (int j=0;j<jsonObject.getJSONArray("subcatchments").size();j++)
            {
                subcatchments[j]=jsonObject.getJSONArray("subcatchments").get(j).toString();
            }
            report.setSubcatchments(subcatchments);
        }
        else
        {
            report.setSubcatchments(null);
        }

        if(jsonObject.getJSONArray("nodes").size()>0)
        {
            String[] nodes=new String[jsonObject.getJSONArray("nodes").size()];
            for (int j=0;j<jsonObject.getJSONArray("nodes").size();j++)
            {
                nodes[j]=jsonObject.getJSONArray("nodes").get(j).toString();
            }
            report.setNodes(nodes);
        }
        else
        {
            report.setNodes(null);
        }

        if(jsonObject.getJSONArray("links").size()>0)
        {
            String[] links=new String[jsonObject.getJSONArray("links").size()];
            for (int j=0;j<jsonObject.getJSONArray("links").size();j++)
            {
                links[j]=jsonObject.getJSONArray("links").get(j).toString();
            }
            report.setLinks(links);
        }
        else
        {
            report.setLinks(null);
        }



        return report;
    }

    private ArrayList<InpData.Tag> getTagFromJson(JSONArray jsonArray)
    {
        ArrayList<InpData.Tag> tagArrayList=new ArrayList<>();

        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Tag tag = inpData.new Tag();
            tag.setCategory(jsonArray.getJSONObject(i).get("category").toString());
            tag.setTagId(jsonArray.getJSONObject(i).get("tagId").toString());
            tag.setContent(jsonArray.getJSONObject(i).get("content").toString());
            tagArrayList.add(tag);
        }
        return tagArrayList;
    }

    private InpData.Map getMapFromJson(JSONObject jsonObject)
    {

        InpData.Map map=inpData.new Map();

        if(jsonObject.getJSONArray("dimensions").size()>0)
        {
            float[] dimensions=new float[4];
            for (int j=0;j<jsonObject.getJSONArray("dimensions").size();j++)
            {
                dimensions[j]=Float.parseFloat(jsonObject.getJSONArray("dimensions").get(j).toString());
            }
            map.setDimensions(dimensions);
        }
        else
        {
            map.setDimensions(null);
        }

        map.setUnits(jsonObject.get("units").toString());

        return map;
    }

    private ArrayList<InpData.Coordinate> getCoordinateFromJson(JSONArray jsonArray)
    {
        ArrayList<InpData.Coordinate> coordinateArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Coordinate coordinate=inpData.new Coordinate();
            coordinate.setNode(jsonArray.getJSONObject(i).get("node").toString());


            coordinate.setX_coord(Float.parseFloat(jsonArray.getJSONObject(i).get("x_coord").toString()));
            coordinate.setY_coord(Float.parseFloat(jsonArray.getJSONObject(i).get("y_coord").toString()));


            coordinateArrayList.add(coordinate);
        }
        return coordinateArrayList;
    }

    private ArrayList<InpData.Vertice> getVerticeFromJson(JSONArray jsonArray)
    {
        ArrayList<InpData.Vertice> verticeArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Vertice vertice=inpData.new Vertice();
            vertice.setLink(jsonArray.getJSONObject(i).get("link").toString());
            vertice.setX_coord(Float.parseFloat(jsonArray.getJSONObject(i).get("x_coord").toString()));
            vertice.setY_coord(Float.parseFloat(jsonArray.getJSONObject(i).get("y_coord").toString()));

            verticeArrayList.add(vertice);
        }
        return verticeArrayList;
    }

    private ArrayList<InpData.Polygon> getPolygonFromJson(JSONArray jsonArray)
    {
        ArrayList<InpData.Polygon> polygonArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Polygon polygon=inpData.new Polygon();
            polygon.setPolygon(jsonArray.getJSONObject(i).get("polygon").toString());
            polygon.setX_coord(Float.parseFloat(jsonArray.getJSONObject(i).get("x_coord").toString()));
            polygon.setY_coord(Float.parseFloat(jsonArray.getJSONObject(i).get("y_coord").toString()));

            polygonArrayList.add(polygon);
        }
        return polygonArrayList;
    }

    private ArrayList<InpData.Symbol> getSymbolFromJson(JSONArray jsonArray)
    {
        ArrayList<InpData.Symbol> symbolArrayList=new ArrayList<>();
        for(int i=0;i<jsonArray.size();i++)
        {
            InpData.Symbol symbol=inpData.new Symbol();
            symbol.setGage(jsonArray.getJSONObject(i).get("gage").toString());
            symbol.setX_coord(Float.parseFloat(jsonArray.getJSONObject(i).get("x_coord").toString()));
            symbol.setY_coord(Float.parseFloat(jsonArray.getJSONObject(i).get("y_coord").toString()));

            symbolArrayList.add(symbol);
        }
        return symbolArrayList;
    }



}
